package com.csi.sai.utilities.templates.selects;

import java.sql.ResultSet;
import java.sql.SQLException;

public class CmbClient implements ComponentTemplate {
	private String htmlCode;
	
	@Override
	public void setRS(ResultSet rs) throws SQLException {
		StringBuffer sb = new StringBuffer();
		sb.append("<select id=\"gCmbClient\" class=\"combo\" onchange=\"comboDrillDown(3)\">");
		sb.append("<option id=\"0\">Selecciona</option>");
		while(rs.next()) {
			sb.append("<option id=\""+rs.getString(1)+"\">"+rs.getString(2)+"</option>");
		}
		sb.append("</select>");
		htmlCode = sb.toString();
	}

	@Override
	public void setRS(ResultSet rs, int idSelected) throws SQLException {
		// TODO Auto-generated method stub
		StringBuffer sb = new StringBuffer();
		sb.append("<select id=\"gCmbClient\" class=\"combo\" onchange=\"comboDrillDown(3)\">");
		sb.append("<option id=\"0\">Selecciona</option>");
		while(rs.next()) {
			if(idSelected==rs.getInt(1)) {
				sb.append("<option selected=\"selected\" id=\""+rs.getString(1)+"\">"+rs.getString(2)+"</option>");
			} else {
				sb.append("<option id=\""+rs.getString(1)+"\">"+rs.getString(2)+"</option>");
			}
		}
		sb.append("</select>");
		htmlCode = sb.toString();
	}

	@Override
	public String getComponentGeneric() {
		// TODO Auto-generated method stub
		return htmlCode;
	}

}
